package com.cskaoyan.service.wx;

import com.cskaoyan.bean.Brand;
import com.cskaoyan.bean.wxbean.BrandQueryBo;
import com.cskaoyan.bean.wxbean.BrandsQueryVO;
import com.cskaoyan.mapper.wx.WxBrandMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Enzo Cotter on 2020/10/8.
 */
@Service
public class WxBrandListServiceImpl implements WxBrandListService {
    @Autowired
    WxBrandMapper wxBrandMapper;

    @Override
    public BrandsQueryVO queryBrands(Integer page, Integer size) {
        BrandsQueryVO brandsQueryVO = new BrandsQueryVO();
        PageHelper.startPage(page,size);
        List<BrandQueryBo> brands = wxBrandMapper.selectBrands();
        PageInfo pageInfo = new PageInfo(brands);
        int pages = pageInfo.getPages();
        brandsQueryVO.setTotalPages(pages);
        brandsQueryVO.setBrandList(brands);
        return brandsQueryVO;
    }

    @Override
    public Brand getBrandById(Integer id) {
        return wxBrandMapper.getBrandById(id);
    }
}
